package cn.wolfcode.wolf2w.controller;


import cn.wolfcode.wolf2w.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.query.QueryObject;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {

	@Autowired
	private IStrategyCatalogService strategyCatalogService;

	@RequestMapping("/list")
	public String query(Model model, @ModelAttribute("qo") QueryObject qo){
		Page page = strategyCatalogService.query(qo);
		model.addAttribute("page",page);
		return "strategyCatalog/list";
	}

	@RequestMapping("/delete")
	@ResponseBody
	public Object delete(String id){
		strategyCatalogService.delete(id);
		return JsonResult.success();
	}

	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public Object saveOrUpdate(StrategyCatalog strategyCatalog){
		if(strategyCatalog.getId() != null){
			strategyCatalogService.update(strategyCatalog);
		}else {
			strategyCatalogService.save(strategyCatalog);
		}
		return JsonResult.success();
	}
}
